<!DOCTYPE html>
<html lang=en>
<head>
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5" />
    <meta name="description" content="ResMq，即基于Redis Stream实现的消息队列。这是一个轻量级的消息队列中间件。严重依赖Redis。 很长一段时间以来，许多开发人员将Redis用作简单的消息队列。他们通常使用Redis的List或Pub&#x2F;Sub数据类型。在Redis引入了Stream类型后，非常适合做消息队列。 为了获得更好的开发体验，我把它打包成一个更专业的消息队列中间件，适配Java17+、SpringB">
<meta property="og:type" content="article">
<meta property="og:title" content="我开源了一款基于Redis Stream封装的轻量级消息队列">
<meta property="og:url" content="https://cheung0-bit.github.io/fa01deca3ae9/index.html">
<meta property="og:site_name" content="Bruce Zhang&#39;s Blogs">
<meta property="og:description" content="ResMq，即基于Redis Stream实现的消息队列。这是一个轻量级的消息队列中间件。严重依赖Redis。 很长一段时间以来，许多开发人员将Redis用作简单的消息队列。他们通常使用Redis的List或Pub&#x2F;Sub数据类型。在Redis引入了Stream类型后，非常适合做消息队列。 为了获得更好的开发体验，我把它打包成一个更专业的消息队列中间件，适配Java17+、SpringB">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20240204144433585.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20240409144014635.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20240409143548079.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20240409143623118.png">
<meta property="og:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20240409143842534.png">
<meta property="article:published_time" content="2024-03-04T13:43:01.000Z">
<meta property="article:modified_time" content="2024-04-10T10:50:01.334Z">
<meta property="article:author" content="张林">
<meta property="article:tag" content="Redis">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20240204144433585.png">
    
    
      
        
          <link rel="shortcut icon" href="/images/favicon.ico">
        
      
      
        
          <link rel="icon" type="image/png" href="/images/favicon-192x192.png" sizes="192x192">
        
      
      
        
          <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
        
      
    
    <!-- title -->
    <title>我开源了一款基于Redis Stream封装的轻量级消息队列</title>
    <!-- styles -->
    
<link rel="stylesheet" href="/css/style.css">

    <!-- persian styles -->
    
    <!-- rss -->
    
    
      <link rel="alternate" href="/atom.xml" title="Bruce Zhang&#39;s Blogs" type="application/atom+xml" />
    
	<!-- mathjax -->
	
<meta name="generator" content="Hexo 7.0.0"></head>

<body class="max-width mx-auto px3 ltr">
    
      <div id="header-post">
  <a id="menu-icon" href="#" aria-label="Menu"><i class="fas fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#" aria-label="Menu"><i class="fas fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" aria-label="Top" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fas fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
        <!--
       --><li><a href="/">Home</a></li><!--
     --><!--
       --><li><a href="/about/">About</a></li><!--
     --><!--
       --><li><a href="/archives/">Articles</a></li><!--
     --><!--
       --><li><a href="/categories/">Category</a></li><!--
     --><!--
       --><li><a href="/search/">Search</a></li><!--
     -->
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        <li><a class="icon" aria-label="Previous post" href="/dcf72531e103/"><i class="fas fa-chevron-left" aria-hidden="true" onmouseover="$('#i-prev').toggle();" onmouseout="$('#i-prev').toggle();"></i></a></li>
        
        
        <li><a class="icon" aria-label="Next post" href="/a848e8f430b2/"><i class="fas fa-chevron-right" aria-hidden="true" onmouseover="$('#i-next').toggle();" onmouseout="$('#i-next').toggle();"></i></a></li>
        
        <li><a class="icon" aria-label="Back to top" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" aria-label="Share post" href="#"><i class="fas fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">Previous post</span>
      <span id="i-next" class="info" style="display:none;">Next post</span>
      <span id="i-top" class="info" style="display:none;">Back to top</span>
      <span id="i-share" class="info" style="display:none;">Share post</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.facebook.com/sharer.php?u=https://cheung0-bit.github.io/fa01deca3ae9/"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://twitter.com/share?url=https://cheung0-bit.github.io/fa01deca3ae9/&text=我开源了一款基于Redis Stream封装的轻量级消息队列"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.linkedin.com/shareArticle?url=https://cheung0-bit.github.io/fa01deca3ae9/&title=我开源了一款基于Redis Stream封装的轻量级消息队列"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://pinterest.com/pin/create/bookmarklet/?url=https://cheung0-bit.github.io/fa01deca3ae9/&is_video=false&description=我开源了一款基于Redis Stream封装的轻量级消息队列"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=我开源了一款基于Redis Stream封装的轻量级消息队列&body=Check out this article: https://cheung0-bit.github.io/fa01deca3ae9/"><i class="fas fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://getpocket.com/save?url=https://cheung0-bit.github.io/fa01deca3ae9/&title=我开源了一款基于Redis Stream封装的轻量级消息队列"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://reddit.com/submit?url=https://cheung0-bit.github.io/fa01deca3ae9/&title=我开源了一款基于Redis Stream封装的轻量级消息队列"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.stumbleupon.com/submit?url=https://cheung0-bit.github.io/fa01deca3ae9/&title=我开源了一款基于Redis Stream封装的轻量级消息队列"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://digg.com/submit?url=https://cheung0-bit.github.io/fa01deca3ae9/&title=我开源了一款基于Redis Stream封装的轻量级消息队列"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.tumblr.com/share/link?url=https://cheung0-bit.github.io/fa01deca3ae9/&name=我开源了一款基于Redis Stream封装的轻量级消息队列&description="><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://news.ycombinator.com/submitlink?u=https://cheung0-bit.github.io/fa01deca3ae9/&t=我开源了一款基于Redis Stream封装的轻量级消息队列"><i class="fab fa-hacker-news " aria-hidden="true"></i></a></li>
</ul>

    </div>
    <div id="toc">
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A2%86%E5%9F%9F%E6%A8%A1%E5%9E%8B"><span class="toc-number">1.</span> <span class="toc-text">领域模型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8A%9F%E8%83%BD%E7%89%B9%E6%80%A7"><span class="toc-number">2.</span> <span class="toc-text">功能特性</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B"><span class="toc-number">3.</span> <span class="toc-text">快速开始</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BE%9D%E8%B5%96"><span class="toc-number">3.1.</span> <span class="toc-text">依赖</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE"><span class="toc-number">3.2.</span> <span class="toc-text">配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%94%9F%E4%BA%A7%E8%80%85"><span class="toc-number">3.3.</span> <span class="toc-text">生产者</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B6%88%E8%B4%B9%E8%80%85"><span class="toc-number">3.4.</span> <span class="toc-text">消费者</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%9B%91%E6%8E%A7%E7%9C%8B%E6%9D%BF"><span class="toc-number">4.</span> <span class="toc-text">监控看板</span></a></li></ol>
    </div>
  </span>
</div>

    
    <div class="content index py4">
        
        <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle" itemprop="name headline">
        我开源了一款基于Redis Stream封装的轻量级消息队列
    </h1>



    <div class="meta">
      <span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span itemprop="name">张林</span>
      </span>
      
    <div class="postdate">
      
        <time datetime="2024-03-04T13:43:01.000Z" itemprop="datePublished">2024-03-04</time>
        
        (Updated: <time datetime="2024-04-10T10:50:01.334Z" itemprop="dateModified">2024-04-10</time>)
        
      
    </div>


      
    <div class="article-category">
        <i class="fas fa-archive"></i>
        <a class="category-link" href="/categories/%E5%BC%80%E5%8F%91%E5%AE%9E%E8%B7%B5/">开发实践</a>
    </div>


      
    <div class="article-tag">
        <i class="fas fa-tag"></i>
        <a class="tag-link-link" href="/tags/Redis/" rel="tag">Redis</a>
    </div>


    </div>
  </header>
  

  <div class="content" itemprop="articleBody">
    <p>ResMq，即基于Redis Stream实现的消息队列。这是一个轻量级的消息队列中间件。严重依赖Redis。</p>
<p>很长一段时间以来，许多开发人员将Redis用作简单的消息队列。他们通常使用Redis的List或Pub&#x2F;Sub数据类型。在Redis引入了Stream类型后，非常适合做消息队列。</p>
<p>为了获得更好的开发体验，我把它打包成一个更专业的消息队列中间件，适配Java17+、SpringBoot3+</p>
<h2 id="领域模型"><a href="#领域模型" class="headerlink" title="领域模型"></a>领域模型</h2><p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20240204144433585.png" alt="image-20240204144433585"></p>
<h2 id="功能特性"><a href="#功能特性" class="headerlink" title="功能特性"></a>功能特性</h2><ul>
<li><strong>轻量级</strong> :  仅依赖于Redis</li>
<li><strong>及时投递</strong> :  即时在后台执行此消息</li>
<li><strong>延迟投递</strong> :  通过Redis的ZSet数据类型，实现了延迟队列</li>
<li><strong>消息可靠性</strong> :  Lua脚本确保消息从生产者传递到代理。Redis Stream提供了XACK机制，让用户确认收到了消息。消费而没有ACK的消息被添加到Pending队列</li>
<li><strong>自动确认</strong> :  ResMq可以在适当的时机自动进行ACK</li>
<li><strong>死信队列</strong>:  触发某些阈值的消息被放入死消息队列，供开发人员后续处理</li>
<li><strong>消息多播</strong> :  消息可以传递给不同的分组</li>
<li><strong>顺序消费</strong> :  消息可以按顺序消费</li>
<li><strong>消息堆积</strong> :  Redis Stream可以存储消息。开发人员可以设置上限来触发自动剔除策略</li>
<li><strong>消息不丢失</strong> :  依靠Redis的RDB&#x2F;AOF持久化机制，可以在很大程度上保证消息丢失，但不能100%保证</li>
<li><strong>伸缩性</strong>:  可以通过搭建Redis主从集群和哨兵集群来提高可用性</li>
<li><strong>开箱即用</strong> :  适应SpringBoot3+，注解式监听，easy code</li>
<li><strong>监控看板</strong>:  做一些简单的数据监控</li>
</ul>
<h2 id="快速开始"><a href="#快速开始" class="headerlink" title="快速开始"></a>快速开始</h2><h3 id="依赖"><a href="#依赖" class="headerlink" title="依赖"></a>依赖</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.github.cheung0-bit<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>resmq-spring-boot-starter<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>$&#123;latestVersion&#125;<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="配置"><a href="#配置" class="headerlink" title="配置"></a>配置</h3><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">res-mq:</span></span><br><span class="line">  <span class="comment"># ------- Required -------</span></span><br><span class="line">  <span class="attr">enable:</span> <span class="literal">true</span></span><br><span class="line">  <span class="comment"># ------- Optional -------</span></span><br><span class="line">  <span class="attr">streams:</span></span><br><span class="line">    <span class="attr">email-send:</span></span><br><span class="line">      <span class="attr">topic:</span> <span class="string">redis-topic</span></span><br><span class="line">      <span class="attr">group:</span> <span class="string">default-group</span></span><br><span class="line">    <span class="attr">log-service:</span></span><br><span class="line">      <span class="attr">topic:</span> <span class="string">sys-log</span></span><br><span class="line">      <span class="attr">group:</span> <span class="string">default-group</span></span><br><span class="line">    <span class="attr">order-service:</span></span><br><span class="line">      <span class="attr">topic:</span> <span class="string">order-service</span></span><br><span class="line">      <span class="attr">group:</span> <span class="string">nanjing-group</span></span><br><span class="line">    <span class="attr">video-transcode:</span></span><br><span class="line">      <span class="attr">topic:</span> <span class="string">video-transcode</span></span><br><span class="line">      <span class="attr">group:</span> <span class="string">my-group</span></span><br><span class="line">  <span class="attr">max-queue-size:</span> <span class="number">1000</span></span><br><span class="line">  <span class="attr">dead-message-delivery-count:</span> <span class="number">1</span></span><br><span class="line">  <span class="attr">dead-message-delivery-second:</span> <span class="number">60</span></span><br><span class="line">  <span class="attr">dead-message-scheduled-thread-pool-core-size:</span> <span class="number">2</span></span><br><span class="line">  <span class="attr">dead-message-timer-initial-delay:</span> <span class="number">30</span></span><br><span class="line">  <span class="attr">dead-message-timer-delay:</span> <span class="number">30</span></span><br><span class="line">  <span class="attr">pending-messages-pull-count:</span> <span class="number">10</span></span><br></pre></td></tr></table></figure>

<p>ResMq只有在enable为true时才能工作，简单业务模式下，可以使用streams配置简单主题和分组。消费者部分中会具体描述什么是简单业务主题和分组</p>
<h3 id="生产者"><a href="#生产者" class="headerlink" title="生产者"></a>生产者</h3><p>先定义一个实体类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="meta">@NoArgsConstructor</span></span><br><span class="line"><span class="meta">@AllArgsConstructor</span></span><br><span class="line"><span class="meta">@ToString</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Email</span> &#123;</span><br><span class="line">    String title;</span><br><span class="line">    String text;</span><br><span class="line">    String author;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>发送消息</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Resource</span></span><br><span class="line"><span class="keyword">private</span> ResMqTemplate resMqTemplate; <span class="comment">// io.github.resmq.core.template.ResMqTemplate</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// Sync Send</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">sendRedisMessage</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">Email</span> <span class="variable">email</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Email</span>(<span class="string">&quot;test email&quot;</span>, <span class="string">&quot;nothing&quot;</span>, <span class="string">&quot;bruce&quot;</span>);</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        resMqTemplate.syncSend(<span class="string">&quot;redis-topic&quot;</span>, email);</span><br><span class="line">    &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// Sync Delay Send</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">sendRedisDelayMessage</span><span class="params">()</span> <span class="keyword">throws</span> InterruptedException &#123;</span><br><span class="line">    <span class="type">Email</span> <span class="variable">email</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Email</span>(<span class="string">&quot;test email &quot;</span> + i + j, <span class="string">&quot;something&quot;</span>, <span class="string">&quot;bruce&quot;</span>);</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        resMqTemplate.syncDelaySend(<span class="string">&quot;redis-topic&quot;</span>, email, <span class="number">10</span>, TimeUnit.SECONDS);</span><br><span class="line">    &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="消费者"><a href="#消费者" class="headerlink" title="消费者"></a>消费者</h3><p>当你的业务非常简单明了时，比如RabbitMQ的<a target="_blank" rel="noopener" href="https://rabbitmq.com/tutorials/tutorial-one-java.html">Hello World</a>模式，你可以选择直接在yml文件中配置业务名称，以及业务名称下的主题和组信息</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">streams:</span></span><br><span class="line">  <span class="attr">email-send:</span></span><br><span class="line">    <span class="attr">topic:</span> <span class="string">redis-topic</span></span><br><span class="line">    <span class="attr">group:</span> <span class="string">default-group</span></span><br></pre></td></tr></table></figure>

<p>这表明存在电子邮件发送业务，redis提供了主题队列和组来工作。在这种情况下，生产者和消费者可以进行一对一的消费(因为只有一个组，所以不可能进行双重消费)。我们可以这样编码</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">String</span> <span class="variable">BUSINESS_NAME</span> <span class="operator">=</span> <span class="string">&quot;email-send&quot;</span>;</span><br><span class="line"></span><br><span class="line"><span class="meta">@ResMqListener(name = BUSINESS_NAME)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">receiveByName</span><span class="params">(Email email)</span> &#123;</span><br><span class="line">    log.info(<span class="string">&quot;[&#123;&#125;]Receive Message---&gt;&#123;&#125;&quot;</span>, <span class="string">&quot;through business name&quot;</span>, email);</span><br><span class="line">    <span class="comment">// ...</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>通过注释直接配置主题和组也很方便</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@ResMqListener(topic = &quot;redis-topic&quot;, group = &quot;group1&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">receiveByTopicGroup1</span><span class="params">(Email email)</span> &#123;</span><br><span class="line">    log.info(<span class="string">&quot;[&#123;&#125;]Receive Message---&gt;&#123;&#125;&quot;</span>, <span class="string">&quot;through topic1 group1&quot;</span>, email);</span><br><span class="line">    <span class="comment">// ...</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">@ResMqListener(topic = &quot;redis-topic&quot;, group = &quot;group2&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">receiveByTopicGroup2</span><span class="params">(Email email)</span> &#123;</span><br><span class="line">    log.info(<span class="string">&quot;[&#123;&#125;]Receive Message---&gt;&#123;&#125;&quot;</span>, <span class="string">&quot;through topic1 group2&quot;</span>, email);</span><br><span class="line">    <span class="comment">// ...</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="监控看板"><a href="#监控看板" class="headerlink" title="监控看板"></a>监控看板</h2><p>url : http:&#x2F;&#x2F;{ip}:{port}</p>
<p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20240409144014635.png" alt="image-20240409144014635"></p>
<p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20240409143548079.png" alt="image-20240409143548079"></p>
<p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20240409143623118.png" alt="image-20240409143623118"></p>
<p><img src="https://0-bit.oss-cn-beijing.aliyuncs.com/image-20240409143842534.png" alt="image-20240409143842534"></p>

  </div>
</article>


    <div class="blog-post-comments">
        <div id="utterances_thread">
            <noscript>Please enable JavaScript to view the comments.</noscript>
        </div>
    </div>


        
          <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
         
          <li><a href="/">Home</a></li>
         
          <li><a href="/about/">About</a></li>
         
          <li><a href="/archives/">Articles</a></li>
         
          <li><a href="/categories/">Category</a></li>
         
          <li><a href="/search/">Search</a></li>
        
      </ul>
    </div>

    <div id="toc-footer" style="display: none">
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A2%86%E5%9F%9F%E6%A8%A1%E5%9E%8B"><span class="toc-number">1.</span> <span class="toc-text">领域模型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8A%9F%E8%83%BD%E7%89%B9%E6%80%A7"><span class="toc-number">2.</span> <span class="toc-text">功能特性</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B"><span class="toc-number">3.</span> <span class="toc-text">快速开始</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BE%9D%E8%B5%96"><span class="toc-number">3.1.</span> <span class="toc-text">依赖</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE"><span class="toc-number">3.2.</span> <span class="toc-text">配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%94%9F%E4%BA%A7%E8%80%85"><span class="toc-number">3.3.</span> <span class="toc-text">生产者</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B6%88%E8%B4%B9%E8%80%85"><span class="toc-number">3.4.</span> <span class="toc-text">消费者</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%9B%91%E6%8E%A7%E7%9C%8B%E6%9D%BF"><span class="toc-number">4.</span> <span class="toc-text">监控看板</span></a></li></ol>
    </div>

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.facebook.com/sharer.php?u=https://cheung0-bit.github.io/fa01deca3ae9/"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://twitter.com/share?url=https://cheung0-bit.github.io/fa01deca3ae9/&text=我开源了一款基于Redis Stream封装的轻量级消息队列"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.linkedin.com/shareArticle?url=https://cheung0-bit.github.io/fa01deca3ae9/&title=我开源了一款基于Redis Stream封装的轻量级消息队列"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://pinterest.com/pin/create/bookmarklet/?url=https://cheung0-bit.github.io/fa01deca3ae9/&is_video=false&description=我开源了一款基于Redis Stream封装的轻量级消息队列"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=我开源了一款基于Redis Stream封装的轻量级消息队列&body=Check out this article: https://cheung0-bit.github.io/fa01deca3ae9/"><i class="fas fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://getpocket.com/save?url=https://cheung0-bit.github.io/fa01deca3ae9/&title=我开源了一款基于Redis Stream封装的轻量级消息队列"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://reddit.com/submit?url=https://cheung0-bit.github.io/fa01deca3ae9/&title=我开源了一款基于Redis Stream封装的轻量级消息队列"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.stumbleupon.com/submit?url=https://cheung0-bit.github.io/fa01deca3ae9/&title=我开源了一款基于Redis Stream封装的轻量级消息队列"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://digg.com/submit?url=https://cheung0-bit.github.io/fa01deca3ae9/&title=我开源了一款基于Redis Stream封装的轻量级消息队列"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.tumblr.com/share/link?url=https://cheung0-bit.github.io/fa01deca3ae9/&name=我开源了一款基于Redis Stream封装的轻量级消息队列&description="><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://news.ycombinator.com/submitlink?u=https://cheung0-bit.github.io/fa01deca3ae9/&t=我开源了一款基于Redis Stream封装的轻量级消息队列"><i class="fab fa-hacker-news fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fas fa-bars fa-lg" aria-hidden="true"></i> Menu</a>
        <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fas fa-list fa-lg" aria-hidden="true"></i> TOC</a>
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fas fa-share-alt fa-lg" aria-hidden="true"></i> Share</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up fa-lg" aria-hidden="true"></i> Top</a>
    </div>

  </div>
</div>

        
        <footer id="footer">
  <div class="footer-left">
    Copyright &copy;
      
        
          2022-2024
            <a target="_blank" rel="noopener" href="https://beian.miit.gov.cn/">
              苏ICP备2022044873号
            </a>
  </div>
  <div class="footer-right">
    <nav>
      <ul>
        
          <!--
       -->
          <li><a href="/">
              Home
            </a></li>
          <!--
     -->
          
          <!--
       -->
          <li><a href="/about/">
              About
            </a></li>
          <!--
     -->
          
          <!--
       -->
          <li><a href="/archives/">
              Articles
            </a></li>
          <!--
     -->
          
          <!--
       -->
          <li><a href="/categories/">
              Category
            </a></li>
          <!--
     -->
          
          <!--
       -->
          <li><a href="/search/">
              Search
            </a></li>
          <!--
     -->
          
      </ul>
    </nav>
  </div>
</footer>
    </div>
    <!-- styles -->


 
  <link
    rel="preload"
    href="/lib/font-awesome/css/all.min.css"
    as="style"
    onload="this.onload=null;this.rel='stylesheet'"
  />
  <noscript
    ><link
      rel="stylesheet"
      href="/lib/font-awesome/css/all.min.css"
  /></noscript>



    <!-- jquery -->
 
  
<script src="/lib/jquery/jquery.min.js"></script>





<!-- clipboard -->

   
    
<script src="/lib/clipboard/clipboard.min.js"></script>

  
  <script type="text/javascript">
  $(function() {
    // copy-btn HTML
    var btn = "<span class=\"btn-copy tooltipped tooltipped-sw\" aria-label=\"Copy to clipboard!\">";
    btn += '<i class="far fa-clone"></i>';
    btn += '</span>'; 
    // mount it!
    $(".highlight table").before(btn);
    var clip = new ClipboardJS('.btn-copy', {
      text: function(trigger) {
        return Array.from(trigger.nextElementSibling.querySelectorAll('.code')).reduce((str,it)=>str+it.innerText+'\n','')
      }
    });
    clip.on('success', function(e) {
      e.trigger.setAttribute('aria-label', "Copied!");
      e.clearSelection();
    })
  })
  </script>


<script src="/js/main.js"></script>

<!-- search -->

<!-- Google Analytics -->

<!-- Baidu Analytics -->

  <script type="text/javascript">
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?4484a4a33014b59670c470a6e15a66db";
          var s = document.getElementsByTagName("script")[0];
          s.parentNode.insertBefore(hm, s);
        })();
        </script>

<!-- Cloudflare Analytics -->

<!-- Umami Analytics -->

<!-- Disqus Comments -->

<!-- utterances Comments -->

    <script type="text/javascript">
      var utterances_repo = 'Cheung0-bit/blog-package';
      var utterances_issue_term = 'title';
      var utterances_label = 'Comment';
      var utterances_theme = 'github-dark';

      (function(){
          var script = document.createElement('script');

          script.src = 'https://utteranc.es/client.js';
          script.setAttribute('repo', utterances_repo);
          script.setAttribute('issue-term', 'pathname');
          script.setAttribute('label', utterances_label);
          script.setAttribute('theme', utterances_theme);
          script.setAttribute('crossorigin', 'anonymous');
          script.async = true;
          (document.getElementById('utterances_thread')).appendChild(script);
      }());
  </script>

</body>
</html>
